﻿
<?php
// à¸—à¸³à¸à¸²à¸£à¸£à¸±à¸šà¸„à¹ˆà¸²à¸ˆà¸²à¸ $_POST à¸—à¸µà¹ˆà¸ªà¹ˆà¸‡à¸¡à¸²à¸ˆà¸²à¸à¸Ÿà¸­à¸£à¹Œà¸¡à¸™à¸±à¹‰à¸™ à¹†
//$id = $_POST[''];
$Pre_st = $_POST['Pre_st'];
$name_st = $_POST["Bame_st"];
$sname_st = $_POST['sname_st'];
$id_st = $_POST['id_st'];
$class_st = $_POST['class_st'];
$date_st = $_POST['dateupdate'];
$choid_p = $_POST['choid1'];
$idHave= $_POST['idHave'];
if ($choid_p == 1) {
	$BosPro = "";
	$name_Pro = $_POST['textbox1'];
} else if ($choid_p == 2) {
	$name_Pro = $_POST['project2'];
	$BosPro = $_POST['bproject'];
} else {
	$i = $choid_p - 3;
	$subject = $_POST['subject'];
	//$name_Pro = $_POST['subject'][($i * 2)]; //2*2=4+1=5
	//$BosPro = $_POST['subject'][($i * 2) + 1]; //$name_Pro = $_POST['subject'][($i * 2)]; //2*2=4+1=5
	$idStu = $_POST['idStu'][($i) ]; //$name_Pro = $_POST['subject'][($i * 2)]; //2*2=4+1=5
	$idPro = $_POST['idPro'][($i)]; //
	echo $idStu."<br>";
	echo $idPro."<br>";
}
$txt="";
for($i=0;$i<count($_POST["choidMac"]);$i++)
{
	if(trim($_POST["choidMac"][$i]) != "")
	{
		echo "chkColor $i = ".$_POST["choidMac"][$i]."<br>";
		$txt=$txt.$_POST["choidMac"][$i].",";
	}
}
// à¹€à¸¡à¸·à¹ˆà¸­à¹€à¸£à¸²à¹„à¸”à¹‰à¸„à¹ˆà¸²à¸ˆà¸²à¸à¸Ÿà¸­à¸£à¹Œà¸¡à¸—à¸µà¹ˆà¸ªà¹ˆà¸‡à¸¡à¸²à¹€à¸£à¸µà¸¢à¸šà¸£à¹‰à¸­à¸¢à¹à¸¥à¹‰à¸§ à¹ƒà¸«à¹‰à¹€à¸£à¸²à¸—à¸³à¸à¸²à¸£à¸šà¸±à¸™à¸—à¸¶à¸à¸‚à¹‰à¸­à¸¡à¸¹à¸¥à¹€à¸‚à¹‰à¸²à¹„à¸›à¸—à¸±à¸™à¸—à¸µ à¹‚à¸”à¸¢à¸à¹ˆà¸­à¸™à¸­à¸·à¹ˆà¸™à¸ˆà¸°à¸•à¹‰à¸­à¸‡à¹€à¸Šà¸·à¹ˆà¸­à¸¡à¸•à¹ˆà¸­à¸à¸±à¸šà¸à¸²à¸™à¸‚à¹‰à¸­à¸¡à¸¹à¸¥à¸à¹ˆà¸­à¸™à¸„à¸£à¸±à¸š
mysql_connect("localhost", "root", "");
mysql_select_db("aris");
mysql_query("SET NAMES UTF8");
if ($idHave=="never")
{
	$new_idST = mysql_result(mysql_query("Select Max(substr(id,-3))+1 as MaxID from  student"), 0, "MaxID"); //à¹€à¸¥à¸·à¸­à¸à¹€à¸­à¸²à¸„à¹ˆà¸² id à¸—à¸µà¹ˆà¸¡à¸²à¸à¸—à¸µà¹ˆà¸ªà¸¸à¸”à¹ƒà¸™à¸à¸²à¸™à¸‚à¹‰à¸­à¸¡à¸¹à¸¥à¹à¸¥à¸°à¸šà¸§à¸ 1 à¹€à¸‚à¹‰à¸²à¹„à¸›à¸”à¹‰à¸§à¸¢à¹€à¸¥à¸¢
if ($new_idST == '') { // à¸–à¹‰à¸²à¹„à¸”à¹‰à¹€à¸›à¹‡à¸™à¸„à¹ˆà¸²à¸§à¹ˆà¸²à¸‡ à¸«à¸£à¸·à¸­ null à¸à¹‡à¹à¸ªà¸”à¸‡à¸§à¹ˆà¸²à¸¢à¸±à¸‡à¹„à¸¡à¹ˆà¸¡à¸µà¸‚à¹‰à¸­à¸¡à¸¹à¸¥à¹ƒà¸™à¸à¸²à¸™à¸‚à¹‰à¸­à¸¡à¸¹à¸¥
	$idStu = "st001";
} else {
	$idStu = "st".sprintf("%03d", $new_idST); //à¸–à¹‰à¸²à¹„à¸¡à¹ˆà¹ƒà¸Šà¹ˆà¸„à¹ˆà¸²à¸§à¹ˆà¸²à¸‡
}
$sqlAdd = "INSERT INTO student (id, Pre_st, name_st, sname_st,id_st,class_st,date_st) VALUES('$idStu', '$Pre_st', '$name_st','$sname_st','$id_st','$class_st','$date_st')";
mysql_query($sqlAdd);
} else if($choid_p <3)
{
$i = $choid_p - 3;
$idStu = $_POST['idStu'][0 ]; //$name_Pro = $_POST['subject'][($i * 2)]; //2*2=4+1=5
	//$idPro = $_POST['idPro'][0]; //
	echo $idStu."<br>";
	//echo $idPro."<br>";
}
if($choid_p<3)
{
$new_idST = mysql_result(mysql_query("Select Max(substr(idPro,-3))+1 as MaxID from  project"), 0, "MaxID"); //à¹€à¸¥à¸·à¸­à¸à¹€à¸­à¸²à¸„à¹ˆà¸² id à¸—à¸µà¹ˆà¸¡à¸²à¸à¸—à¸µà¹ˆà¸ªà¸¸à¸”à¹ƒà¸™à¸à¸²à¸™à¸‚à¹‰à¸­à¸¡à¸¹à¸¥à¹à¸¥à¸°à¸šà¸§à¸ 1 à¹€à¸‚à¹‰à¸²à¹„à¸›à¸”à¹‰à¸§à¸¢à¹€à¸¥à¸¢
if ($new_idST == '') { // à¸–à¹‰à¸²à¹„à¸”à¹‰à¹€à¸›à¹‡à¸™à¸„à¹ˆà¸²à¸§à¹ˆà¸²à¸‡ à¸«à¸£à¸·à¸­ null à¸à¹‡à¹à¸ªà¸”à¸‡à¸§à¹ˆà¸²à¸¢à¸±à¸‡à¹„à¸¡à¹ˆà¸¡à¸µà¸‚à¹‰à¸­à¸¡à¸¹à¸¥à¹ƒà¸™à¸à¸²à¸™à¸‚à¹‰à¸­à¸¡à¸¹à¸¥
	$idPro = "p001";
} else {
	$idPro = "p".sprintf("%03d", $new_idST); //à¸–à¹‰à¸²à¹„à¸¡à¹ˆà¹ƒà¸Šà¹ˆà¸„à¹ˆà¸²à¸§à¹ˆà¸²à¸‡
}

$sqlAdd2 = "INSERT INTO project (idPro,type,NPro,bossproject) VALUES('$idPro', $choid_p, '$name_Pro','$BosPro')";
mysql_query($sqlAdd2);
}
$sqlAdd3 = "INSERT INTO result (idPro,idStu,idTool,dateStrat,dateEnd) VALUES('$idPro', '$idStu', '$txt','$date_st','')";
mysql_query($sqlAdd3);
mysql_close();
//echo $sqlAdd;
//echo $sqlAdd2;
//echo $sqlAdd3;
//echo $choid_p;
// à¹€à¸¡à¸·à¹ˆà¸­à¸—à¸³à¸à¸²à¸£à¹€à¸žà¸´à¹ˆà¸¡à¹€à¸ªà¸£à¹‡à¸ˆà¹€à¸£à¸µà¸¢à¸šà¸£à¹‰à¸­à¸¢à¹à¸¥à¹‰à¸§à¹ƒà¸«à¹‰à¸—à¸³à¸à¸²à¸£ redirect à¸«à¸™à¹‰à¸²à¹„à¸›à¸¢à¸±à¸‡à¸«à¸™à¹‰à¸² view.php à¹€à¸¥à¸¢à¸„à¸£à¸±à¸š
header("location: view.php");
?>